package com.gxuwz.medical.context;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * 事务管理器类
 * @author k88
 *
 */
public class TransactionManager {
	
	private Connection conn;
	public TransactionManager(Connection conn){
		this.conn =conn;
	}
	/**
	 * 开启事务
	 * @param autoCommit
	 * @throws SQLException
	 */
	public void beginTransation(boolean autoCommit)throws SQLException{
		/**
		 * 判断连接对象是否关闭
		 */
		if(conn!=null&&conn.isClosed()){
			conn.setAutoCommit(autoCommit);
		}
	}
	/**
	 * 提交事务
	 * @throws SQLException
	 */
	public void endTransation()throws SQLException{
		  conn.commit();
	}
	
	/**
	 * 提交事务
	 * @throws SQLException
	 */
	public void rollbackTransation()throws SQLException{
		  conn.rollback();
	}
}
